import 'package:flutter/material.dart';
import 'package:flutter_cwhisky/common/style/colors.dart';
import 'package:flutter_cwhisky/component/business/memer_good.dart';
import 'package:flutter_cwhisky/component/image_view.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../bean/mall_home_entity.dart';
import '../mall_good.dart';

class OtherPrefectureComponent extends StatelessWidget {
  final MallHomeDataPrefecture prefecture;

  const OtherPrefectureComponent({Key? key, required this.prefecture}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 286.r,
      child: Column(
        children: [_buildBrands(), Expanded(child: _buildGood())],
      ),
    );
  }

  _buildBrands() {
    var item = prefecture.children![0];
    return prefecture.children!.length == 1
        ? Container(
            height: 80.r,
            child: ImageView(
              url: item.image ?? '',
              height: 70.r,
            ),
          )
        : Container(
            height: 80.r,
            padding: EdgeInsets.symmetric(vertical: 10.r),
            child: ListView.builder(
                physics: const BouncingScrollPhysics(),
                itemCount: prefecture.children!.length,
                scrollDirection: Axis.horizontal,
                itemBuilder: (context, index) {
                  return _buildBrandItem(prefecture.children![index], index);
                }),
          );
  }

  _buildBrandItem(MallHomeDataPrefectureChildren item, int index) {
    return Container(
      margin: EdgeInsets.only(left: index == 0 ? 16.r : 16.r),
      decoration: BoxDecoration(color: AppColors.colorF8, borderRadius: BorderRadius.circular(6.r)),
      child: AspectRatio(
        aspectRatio: 1,
        child: ImageView(
          url: item.brandImage,
          width: 58.r,
          height: 58.r,
        ),
      ),
    );
  }

  _buildGood() {
    return ListView.builder(
        physics: const BouncingScrollPhysics(),
        itemCount: prefecture.goods!.length,
        scrollDirection: Axis.horizontal,
        itemBuilder: (context, index) {
          return Container(
            margin: EdgeInsets.only(left: 12.r),
            child: MallGoodView(good: prefecture.goods![index]),
          );
        });
  }
}
